# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
__project__ =  'tricker'
__file__    =  'vnf.py'
__author__  =  'king'
__time__    =  '2024/5/24 16:31'


                              _ooOoo_
                             o8888888o
                             88" . "88
                             (| -_- |)
                             O\  =  /O
                          ____/`---'\____
                        .'  \\|     |//  `.
                       /  \\|||  :  |||//  \
                      /  _||||| -:- |||||-  \
                      |   | \\\  -  /// |   |
                      | \_|  ''\---/''  |   |
                      \  .-\__  `-`  ___/-. /
                    ___`. .'  /--.--\  `. . __
                 ."" '<  `.___\_<|>_/___.'  >'"".
                | | :  `- \`.;`\ _ /`;.`/ - ` : | |
                \  \ `-.   \_ __\ /__ _/   .-` /  /
           ======`-.____`-.___\_____/___.-`____.-'======
                              `=---='
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       佛祖保佑        永无BUG
"""
from tricker.common.models import Base


class Image(Base):
    def __init__(self, *args, **kwargs):
        self.id = ''
        self.version = ''
        self.hash = ''
        self.algorithm = 'sha-512'
        self.min_disk = ''
        self.size = 0
        self.container_format = ''
        self.disk_format = ''
        self.file = ''
        super().__init__(*args, **kwargs)


class Flavor(Base):
    def __init__(self, *args, **kwargs):
        self.id = ''
        self.mem = ''
        self.vcpu = 1
        self.disk = 0
        super().__init__(*args, **kwargs)


class Network(Base):
    def __init__(self, *args, **kwargs):
        self.fixed_ip = ''
        self.floating_ip = ''
        self.id = ''
        self.port = ''

        self.connect_point = ''
        self.cidr = ''
        super().__init__(*args, **kwargs)

    def __str__(self) -> str:
        return f'<{self.id}, {self.cidr}>'


class Server(Base):
    def __init__(self, *args, **kwargs):
        self.name = ''
        self.max_count = 3
        self.min_count = 0
        super().__init__(*args, **kwargs)


class VNF(Base):
    def __init__(self, *args, **kwargs):
        self.name = ''
        self.VNFD = ''
        self.version = ''
        self.provider = ''
        self.product = ''
        self.software_version = ''
        self.flavour_id = ''
        self.flavour_description = ''
        super(VNF, self).__init__(*args, **kwargs)


class Entity(Base):
    def __init__(self, *args, **kwargs):
        self.image = None
        self.flavor = None
        self.network = None
        self.server = None
        self.VNF = None
        super().__init__(*args, **kwargs)

    def __str__(self) -> str:
        return (
            f'<image: {self.image.id}, '
            f'flavor: {self.flavor.id}, '
            f'network: {self.network}, '
            f'server: {self.server.name}, '
            f'VNF: {self.VNF.name}>'
        )


class CASR(object):
    BaseHOT = 'BaseHOT/%(flavour_id)s'
    BaseHOT_Nested = 'BaseHOT/%(flavour_id)s/nested'
    Definitions = 'Definitions'
    Files = 'Files'
    TOSCA_Metadata = 'TOSCA-Metadata'
    UserData = 'UserData'
    ALL = (
        BaseHOT,
        BaseHOT_Nested,
        Definitions,
        Files,
        TOSCA_Metadata,
        UserData,
    )
    DEV_PATH = './CASR/'

    @classmethod
    def file_mappings(cls) -> dict:
        return {
            'vnfd_df.yaml': f'{cls.Definitions}/vnfd_df.yaml',
            'vnfd_top.yaml': f'{cls.Definitions}/vnfd_top.yaml',
            'vnfd_types.yaml': f'{cls.Definitions}/vnfd_types.yaml',
            'TOSCA.meta': f'{cls.TOSCA_Metadata}/TOSCA.meta',
            'base_hot.yaml': f'{cls.BaseHOT}/base_hot.yaml',
            'VDU.yaml': f'{cls.BaseHOT_Nested}/VDU.yaml',
            'request.json': f'request.json',
        }

    @classmethod
    def sol001_files(cls):
        return [
            'etsi_nfv_sol001_common_types.yaml',
            'etsi_nfv_sol001_vnfd_types.yaml',
        ]

    @classmethod
    def userdata_files(cls):
        return [
            '__init__.py',
            'user_data.py',
        ]
